<?php 
namespace Admin\Controller;
use Think\Controller;

class NodeController extends AdminController
{

	public function index()
	{
		$data=D('node')->order('id')->select();		
		$this->assign('title','权限表');
		$this->assign('list',$data);
		$this->display('Node/index');
	}

    public function del()
    {
    	if (empty($_GET['id'])) {
    		$this->redirect('Node/index');
    		exit;
    	}
    	$id=I('get.id/d');

    	if (D('node')->delete($id) >0 ) {
    		$this->success('删除成功',U('index'));
    	} else {
    		$this->error('删除失败',U('index'));
    	}
    } 

	public function add()
	{
        $this->assign('title','添加权限');
        $this->display('Node/add');
	}

	public function doadd()
	{
		
		$node=D('node');
		if (!$node->create()) {
			$this->error($node->getError());
		} else {
			if ($node->add() >0 ) {
				$this->success('添加成功',U('index'));
			} else {
				$this->error('添加失败');
			}
		}
	}

	public function edit($id)
	{
		$id = I('get.id/d');
		$data=D('node')->find($id);
		$this->assign('title','修改权限');
		$this->assign('data',$data);
		$this->display('Node/edit');
	}

	public function update()
	{
		if (empty($_POST)) {
			$this->error('请填写相应数据',U('Node/edit'));
			exit;
		}

		D('node')->create();
		// echo D('node')->save();
		// exit;
		if (D('node')->save()) {
			$this->success('修改成功',U('index'));
		} else {
			$this->error('修改失败');
		}
	}
}